#include<bits/stdc++.h>
using namespace std;
int t;
struct car{
    int d,v,a,st,en;
}a[114514];
bool cmp(car a,car b){
    if(a.en!=b.en) return a.en>b.en;
    return a.st<b.st;
}
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);

    cin>>t;
    for(int p1=1;p1<=t;p1++){
        int n,m,l,v,p[114514],ans=0,cou=0;
        bool vis[1145]={0};
        cin>>n>>m>>l>>v;
        for(int i=1;i<=n;i++){
            cin>>a[i].d>>a[i].v>>a[i].a;
            if(a[i].a==0){
                a[i].st=a[i].d,a[i].en=0;
                if(a[i].v>v) a[i].en=l;
            } else {
                int s=(v*v-a[i].v*a[i].v)/a[i].a/2;
                if(a[i].a>0){
                    a[i].st=a[i].d+s+1,a[i].en=l;
                }else{
                    if(s>0) a[i].st=a[i].d,a[i].en=a[i].d+s;
                    else a[i].st=0,a[i].en=0;
                }
            }
        }
        for(int i=1;i<=m;i++) cin>>p[i];
        if(n<=20){
            for(int i=1;i<=n;i++){
                int f=1,fc=1;
                for(int j=1;j<=m;j++){
                    if(p[j]>=a[i].st&&p[j]<=a[i].en){
                        ans+=f,f=0;
                        if(!vis[i]){
                            vis[i]=true;
                            cou+=fc;
                            fc=0;
                        }
                    }
                }
            }
            cout<<ans<<' '<<m-cou<<endl;
        }else{
            sort(a+1,a+n+1,cmp);
            for(int i=n;i>0;i--){
                if(a[i].st>p[m]||a[i].en<p[m]) ans++;
                else break;
            }
            if(ans!=n) cout<<n-ans<<' '<<m-1<<endl;
            else cout<<0<<' '<<m<<endl;
        }
    }

    return 0;
}
